home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 07 - 1991 / 07.09 Sep 91 / Generic Source ƒ / Generic.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-03  |  4.8 KB  |  239 lines  |  [TEXT/KAHL]

  1. #pragma mark Header
  2. /***************************/
  3. /* Generic.c
  4.     This program is to demonstrate some
  5.     of the generic features of THINK C
  6.     and some of the THINK C features for
  7.     debugging and console emulation
  8.     History
  9.     6/5/91 - Created by Kirk Chase */
  10. /***************************/
  11.  
  12. #pragma mark #includes
  13. /* the #pragma directive is ignored by THINK C and is used
  14.     by CMarker by Max Lyth (shareware $20).  CMarker adds a
  15.     box to the window bar that when pressed will display a
  16.     list of all functions and #pragma mark <Name> directives.
  17.     This is useful for quick navigation through a source file.
  18.     You simply select the function or <Name>, and the window
  19.     will scroll to it.  Also you can comment/uncomment blocks
  20.     of code. */
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include <ctype.h>
  24. #include <time.h>
  25. #include "DebugAids.h"
  26.  
  27. #ifdef THINK_C
  28. #include <console.h>
  29. #endif
  30.  
  31. #ifdef PROFILE
  32. #include <profile.h>
  33. #endif
  34.  
  35. #pragma mark #defines
  36. #ifndef TRUE
  37. #define TRUE (1)
  38. #define FALSE (0)
  39. #endif
  40.  
  41. #pragma mark Globals
  42. jmp_buf env;
  43.  
  44. void PrintMenu(void)
  45. /* prints menu choices */
  46. {
  47. printf("\n");
  48. #ifdef THINK_C
  49. printf("\n\t\tΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩ\n");
  50. printf("\t\t™™ MAIN MENU ™™\n");
  51. printf("\t\tΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩ\n\n");
  52.  
  53. printf("†Ã† Command Line Args\t\t");
  54. printf("†¬† Beep Macintosh\n");
  55. printf("†‘† Test Interrupt\t\t");
  56. printf("†¡† Advertisement\n");
  57. printf("†“† Read File\t\t\t");
  58. printf("†√† Copy File\n");
  59. printf("†±† Test Page 1\t\t\t");
  60. printf("†≤† Test Page 2\n");
  61.  
  62. printf("\n†—† Quit\n");
  63. #else
  64. printf("\n\t\t===============\n");
  65. printf("\t\t** MAIN MENU **\n");
  66. printf("\t\t===============\n\n");
  67.  
  68. printf(" L) Command Line Args\t\t");
  69. printf(" B) Beep Macintosh\n");
  70. printf(" T) Test Interrupt\t\t");
  71. printf(" A) Advertisement\n");
  72. printf(" R) Read File\t\t\t");
  73. printf(" C) Copy File\n");
  74. printf(" 1) Test Page 1\t\t\t");
  75. printf(" 2) Test Page 2\n");
  76.  
  77. printf("\n Q) Quit\n");
  78. #endif
  79. }
  80.  
  81. char GetChoice(void)
  82. /* gets menu choices */
  83. {
  84. char command;
  85. char commandSet[10] = "QBTRCLA12\0";
  86. #ifdef PROFILE
  87.     _profile = FALSE;
  88.     _trace = FALSE;
  89. #endif
  90. printf("\n");
  91.  
  92. #ifdef THINK_C
  93. csetmode(C_CBREAK, stdin);
  94. printf("æææ ");
  95. #else
  96. printf(">>> ");
  97. #endif
  98.  
  99. scanf("%c", &command);
  100. command = toupper(command);
  101. while (!strchr(commandSet, command)) { /* loop til command is valid */
  102.     printf("\nType in one of the following letters <%s>\n", commandSet);
  103.     
  104.     #ifdef THINK_C
  105.     printf("\næææ ");
  106.     #else
  107.     printf(">>> ");
  108.     #endif
  109.     scanf("%c", &command);
  110.     command = toupper(command);
  111.     }
  112. printf("\n");
  113.  
  114. #ifdef THINK_C
  115. csetmode(C_ECHO, stdin);
  116. #endif
  117. #ifdef PROFILE
  118.     _profile = TRUE;
  119.     _trace = TRUE;
  120. #endif
  121. return (command);
  122. }
  123.  
  124. void TestInterrupt(void)
  125. /* continous loop until cmd-. is pressed */
  126. {
  127. while (!CheckOptionAbort()) printf("Type COMMAND-. to stop!\n");
  128. }
  129.  
  130. main(int argc, char **argv)
  131. {
  132. /* main entry point */
  133. short i, theSignal;
  134. char com;
  135. FILE *con2=NULL;
  136.  
  137. /* set up */
  138. #ifdef PROFILE
  139. InitProfile(200, 200);
  140. _profile = TRUE;
  141. _trace = TRUE;
  142. #endif
  143.  
  144. #ifdef THINK_C
  145. /* This should go up all the time unless using another environment */
  146. argc = ccommand(&argv);
  147. cinverse(TRUE, stdout);
  148. ccleos(stdout);
  149. printf("You are using THINK C\n");
  150. #else
  151. printf("You are using a PC\n");
  152. #endif
  153.  
  154. #ifdef DEBUG
  155. printf("Debug options are on\n");
  156. #else
  157. printf("Debug options are off\n");
  158. #endif
  159.  
  160. #ifdef DEBUGGER
  161. printf("Debugger options are on\n");
  162. #else
  163. printf("No Debugger\n");
  164. #endif
  165.  
  166. printf("\n");
  167.  
  168. /* set up second console */
  169. InitSecondConsole(&con2);
  170.  
  171. do { /* main loop */
  172.     #ifdef PROFILE
  173.     _profile = FALSE;
  174.     _trace = FALSE;
  175.     #endif
  176.     
  177.     theSignal = setjmp(env); /* set up jump point */
  178.     SigHandler(theSignal); /* do signal handler */
  179.     
  180.     PrintMenu();
  181.     com = GetChoice();
  182.     
  183.     #ifdef PROFILE
  184.     _profile = TRUE;
  185.     _trace = TRUE;
  186.     #endif
  187.     
  188.     switch (com) { /* handle command */
  189.         case 'B':
  190.             printf("\a"); /* '\a' rings bell/beeps Macintosh */
  191.             break;
  192.         case 'T':
  193.             #ifdef PROFILE
  194.             _profile = FALSE; /* cmd-. messes up profiler */
  195.             _trace = FALSE;
  196.             #endif
  197.             
  198.             TestInterrupt(); /* test cmd-. */
  199.             
  200.             #ifdef PROFILE
  201.             _profile = TRUE;
  202.             _trace = TRUE;
  203.             #endif
  204.             
  205.             break;
  206.         case 'R':
  207.             ReadFile(FALSE, con2); /* read a file */
  208.             break;
  209.         case 'C':
  210.             ReadFile(TRUE, con2); /* copy a file */
  211.             break;
  212.         case 'L': /* list command line arguements */
  213.             printf(" #\tArguement\n==\t=========\n");
  214.             for (i=0; i<argc; i++)
  215.                 printf("%d\t%s \n", i, argv[i]);
  216.                 
  217.             #ifdef THINK_C
  218.             printf("\nPress mouse button to continue...\n\n");
  219.             while(!Button()); /* loop until button */
  220.             #endif
  221.             break;
  222.         case 'A':
  223.             SecondConsoleAd(con2); /* advertisement */
  224.             break;
  225.         case '1': /* print columns/rows per page */
  226.         case '2': /* print two pages with forced page break */
  227.             PrintTestPage((short) com - '0');
  228.             break;
  229.         }
  230.     } while (com != 'Q');
  231.  
  232. #ifdef PROFILE
  233. #ifdef THINK_C
  234. cecho2file("Profiler Report", TRUE, stdout); /* output to file */
  235. #endif
  236. printf("***** Profile Report *****\n");
  237. printf("%s\n", ctime(NULL));
  238. #endif
  239. }